package com.xiexuan.cardfragment;

import java.util.ArrayList;
import com.xiexuan.hearthstonecard.CardSetAdapter;
import com.xiexuan.hearthstonecard.CardSetDetail;
import com.xiexuan.hearthstonecard.Cardset;
import com.xiexuan.hearthstonecard.R;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class CardSet_fragment extends Fragment {

	private ListView lv_cardset;
	private ArrayList<Cardset> cardsets = new ArrayList<Cardset>();

	@Override
	public View onCreateView(LayoutInflater inflater,
			@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View view = inflater.inflate(R.layout.cardset_fragment, container,
				false);
		cardsets = Cardset.getCardSets();

		lv_cardset = (ListView) view.findViewById(R.id.lv_cardset);

		CardSetAdapter mAdapter = new CardSetAdapter(cardsets, getActivity());

		lv_cardset.setAdapter(mAdapter);

		lv_cardset.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub

				Intent mIntent = new Intent(getActivity(), CardSetDetail.class);
				mIntent.putExtra("CARDSET", cardsets.get(position));
				getActivity().startActivity(mIntent);
			}
		});

		return view;
	}

}
